package stu.day33_day38.day36;

import java.util.HashMap;

public class test {
    public int maximumUniqueSubarray(int[] nums) {

        int max = 0;
        int left = 0;

        HashMap<Integer,Integer> map = new HashMap<>();
        for(int r=0;r<nums.length;r++){
            int num = nums[r];
            int n = map.getOrDefault(num,0);
            map.put(num,n+1);

            int sum = 0;
            while(!cal(map)){
                int m = nums[left];
                int t = map.get(m);
                if(t==1){
                    map.remove(m);
                }else {
                    map.put(m,t-1);
                }
                left += 1;
            }
            System.out.println();
            for(Integer x:map.keySet()){
                System.out.print(x+" ");
                sum += x;
            }
            max = Math.max(max,sum);
        }
        return max;

    }

    public boolean cal(HashMap<Integer,Integer> map){
        for(Integer x:map.keySet()){
            if(map.get(x)>1){
                return false;
            }
        }
        return true;
    }


    public static void main(String[] args) {

        test t = new test();
        int[] nums = new int[]{4,2,4,5,6};
        t.maximumUniqueSubarray(nums);

    }

}
